using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SonicBloom.Koreo;

public class TestForBeatInput : MonoBehaviour
{
    [EventID]
    [SerializeField]
    public string eventID;
    [SerializeField]
    private float acuraccyRate = 0.4f;

    private float playerHitSpaceTime = 0f;



    private void Awake()
    {
        // register Koregrapher event
        Koreographer.Instance.RegisterForEvents(eventID, OnMusicalTrigger);
        // register input event
        EventHandlerMgr.GetInstance().RegisterHandler((pars) =>
        {
            if(pars[0] is InputCommand command)
            {
                if (command == InputCommand.Space)
                {
                    playerHitSpaceTime = Time.realtimeSinceStartup;
                }
            }

        }, EventName.InputMsg);
    }
    void OnMusicalTrigger(KoreographyEvent evt)
    {
        Debug.Log("Beat!");
        if(Mathf.Abs(playerHitSpaceTime - Time.realtimeSinceStartup) < acuraccyRate)
        {
            Debug.Log("Perfect!!!!!!!!!!");
        }      
    }
}
